/*
 * Copyright (C) 2009, 2010, B3log Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.b3log.nide.action.websocket;

import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.websocket.WebSocket;
import org.eclipse.jetty.websocket.WebSocketServlet;

/**
 * Web socket action for output.
 *
 * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
 * @version 1.0.0.2, Mar 10, 2011
 */
public final class OutputSocketAction extends WebSocketServlet {

    /**
     * Default serial version uid.
     */
    private static final long serialVersionUID = 1L;
    /**
     * Logger.
     */
    private static final Logger LOGGER =
            Logger.getLogger(OutputSocketAction.class.getName());
    /**
     * Outputs stack.
     */
    public static final Stack<OutputSocket> OUTPUT_SOCKETS =
            new Stack<OutputSocket>();

    @Override
    public WebSocket doWebSocketConnect(
            final HttpServletRequest request,
            final String protocol) {
        LOGGER.log(Level.FINE, "WebSocket[protocol={0}] connecting....",
                   protocol);

        final OutputSocket ret = new OutputSocket();
        ret.setRequest(request);
        OUTPUT_SOCKETS.push(ret);

        return ret;
    }
}
